/*
 * ConfigurationInterface.java
 *
 * Created on May 10, 2006, 10:33 AM
 *
 * @author  Francois Daniels
 */
import java.awt.*;
import javax.swing.table.*;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartMouseEvent;
import za.gateway.preferences.Settings;
import za.gateway.io.*;
import za.gateway.backend.*;
import za.gateway.container.*;
import javax.swing.JOptionPane;

public class ConfigurationInterface extends javax.swing.JFrame
        implements ChartMouseListener {
    GroupsInterface groupsInterface;
    PhonesInterface phonesInterface;
    RestrictionsInterface restrictionInterface;
    ChartPanel chartPanel;
    JFreeChart graph;
    AccessControlList ACL;
    
    private static final int rowHeight = 20;
    
    /** Creates new form ConfigurationInterface */
    public ConfigurationInterface () {
        initComponents ();
        configureComponents ();
        updateComponents ();
    }
    
    private void center () {
        Dimension screen = 
                Toolkit.getDefaultToolkit ().getScreenSize ();
        Dimension window = getSize ();
        
        if (window.height > screen.height) {
            window.height = screen.height;
        }
        if (window.width > screen.width) {
            window.width = screen.width;
        }
        int xCoord = (screen.width/2 - window.width/2);
        int yCoord = (screen.height/2 - window.height/2);
        setLocation ( xCoord, yCoord );
        setVisible (true);
    }
    
    private void updateComponents () {
        setTitle ("Configuration Editor");
        update (false);
        groupsInterface = new GroupsInterface (this);
        phonesInterface = new PhonesInterface (this);
        restrictionInterface = new RestrictionsInterface (this);
        ACL = new AccessControlList (Settings.userName, 
                Settings.password, Settings.IP, Settings.database);
        
        if (Settings.isWindows) {
            try {
                javax.swing.UIManager.setLookAndFeel (
                "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                javax.swing.SwingUtilities.
                        updateComponentTreeUI (this);
                pack ();
            } catch (Exception e) { }
        }
        
        graph = getPieChart ();
        chartPanel = new ChartPanel (graph);
        usagePanel.add (chartPanel, java.awt.BorderLayout.CENTER);
        chartPanel.addChartMouseListener (this);
        center ();
    }
    
    public void chartMouseClicked (ChartMouseEvent e) {
        //TODO: Pass it the correct data that should display the graph
        new GraphWindow (this).setVisible (true);
    }
    
    public void chartMouseMoved (ChartMouseEvent e) { }
    
    public JFreeChart getPieChart () {
        DefaultPieDataset dataset = new DefaultPieDataset ();
        dataset.setValue ("March", 60);
        dataset.setValue ("April", 10);
        dataset.setValue ("May", 30);
        JFreeChart graph = ChartFactory.createPieChart3D (
                "Last Three Months",
                dataset,
                true,
                true,
                false);
        PiePlot3D plot = (PiePlot3D) graph.getPlot ();
        plot.setForegroundAlpha ( 0.6f );
        plot.setStartAngle (270);
        plot.setDirection (org.jfree.util.Rotation.ANTICLOCKWISE);
        final Rotator rotator = new Rotator (plot);
        rotator.start ();
        return graph;
    }
    
    public void update (boolean db_dirty) {
        //TODO: Implement update from database to reflect any changes
        AccessControlList ACL =                
                new AccessControlList (Settings.userName,
                Settings.password, Settings.IP, Settings.database);
        AccessControlElement [] Elements = ACL.GetData ();
        
        for (int i = 0; i < Elements.length; i++) {
            ACL_Table.getModel ().setValueAt (
                    Elements [i].GetGroupName (), i, 0);
            ACL_Table.getModel ().setValueAt (
                    Elements [i].GetRestrictionName (), i, 1);
            ACL_Table.getModel ().setValueAt (
                    Elements [i].GetPhoneNumber (), i, 2);
        }
    }
    
    private void configureComponents () {
        Border.setTitleAt (0, "Access Contol List");
        Border.setTitleAt (1, "Call Detail Records");
    }
    
    private void addRow (String group, String restriction, 
            String number) {
        
        DefaultTableModel model = 
                (DefaultTableModel) ACL_Table.getModel ();
        
        String data [] = new String [3];
        data [0] = group;
        data [1] = restriction;
        data [2] = number;
        model.addRow (data);
    }
    
    
    // <editor-fold defaultstate="collapsed" desc=" Code generated by Netbeans for the GUI Components  ">
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        javax.swing.JPanel ACL_Border;
        javax.swing.JPanel CDR_Border;
        javax.swing.JSeparator helpSeparator;
        javax.swing.JSeparator opsSeparator;
        javax.swing.JSeparator opsSeparator2;

        graphButtonGroup = new javax.swing.ButtonGroup();
        Border = new javax.swing.JTabbedPane();
        ACL_Border = new javax.swing.JPanel();
        tableScroll = new javax.swing.JScrollPane();
        ACL_Table = new javax.swing.JTable();
        CDR_Border = new javax.swing.JPanel();
        cdrTablePanel = new javax.swing.JScrollPane();
        cdrTable = new javax.swing.JTable();
        cdrGraphPanel = new javax.swing.JPanel();
        groupByPanel = new javax.swing.JPanel();
        destinationRadioButton = new javax.swing.JRadioButton();
        groupRadioButton = new javax.swing.JRadioButton();
        dateRadioButton = new javax.swing.JRadioButton();
        graphPanel = new javax.swing.JPanel();
        rangeList = new javax.swing.JComboBox();
        dataList = new javax.swing.JComboBox();
        displayGraphButton = new javax.swing.JButton();
        usagePanel = new javax.swing.JPanel();
        Menu = new javax.swing.JMenuBar();
        opsMenu = new javax.swing.JMenu();
        addACL = new javax.swing.JMenuItem();
        editACL = new javax.swing.JMenuItem();
        removeACL = new javax.swing.JMenuItem();
        opsSeparator = new javax.swing.JSeparator();
        configGroups = new javax.swing.JMenuItem();
        configPhones = new javax.swing.JMenuItem();
        configRestrictions = new javax.swing.JMenuItem();
        opsSeparator2 = new javax.swing.JSeparator();
        exitItem = new javax.swing.JMenuItem();
        saveItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpIndex = new javax.swing.JMenuItem();
        helpSeparator = new javax.swing.JSeparator();
        helpAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        ACL_Border.setLayout(new java.awt.BorderLayout());

        ACL_Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Group", "Restriction", "Number"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableScroll.setViewportView(ACL_Table);

        ACL_Border.add(tableScroll, java.awt.BorderLayout.CENTER);

        Border.addTab("tab1", ACL_Border);

        CDR_Border.setLayout(new java.awt.BorderLayout());

        cdrTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"2006-03-04 13:45", "Nurses", "Lwendile Clinic", "Canzibe Hospital", "03:34"},
                {"2006-03-04 14:15", "Doctors", "Canzibe Hospital", "Canzibe Dispensary", "01:12"},
                {"2006-03-04 14:43", "Dr. Mzabel", "Canzibe Hospital", "National Number", "05:33"},
                {"2006-03-04 15:12", "Nurses", "Lwendile Clinic", "Canzibe Hospital", "02:15"},
                {"2006-03-04 16:04", "Nurses", "Lwendile Clinic", "Canzibe Hospital", "04:49"},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Calldate", "Group", "Source", "Destination", "Duration"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        cdrTablePanel.setViewportView(cdrTable);

        CDR_Border.add(cdrTablePanel, java.awt.BorderLayout.CENTER);

        groupByPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Arrange by"));
        graphButtonGroup.add(destinationRadioButton);
        destinationRadioButton.setText("Destination");
        destinationRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        destinationRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        graphButtonGroup.add(groupRadioButton);
        groupRadioButton.setText("Group");
        groupRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        groupRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        graphButtonGroup.add(dateRadioButton);
        dateRadioButton.setSelected(true);
        dateRadioButton.setText("Date");
        dateRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        dateRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        org.jdesktop.layout.GroupLayout groupByPanelLayout = new org.jdesktop.layout.GroupLayout(groupByPanel);
        groupByPanel.setLayout(groupByPanelLayout);
        groupByPanelLayout.setHorizontalGroup(
            groupByPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(groupByPanelLayout.createSequentialGroup()
                .add(groupByPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(groupRadioButton)
                    .add(destinationRadioButton)
                    .add(dateRadioButton))
                .addContainerGap(180, Short.MAX_VALUE))
        );
        groupByPanelLayout.setVerticalGroup(
            groupByPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(groupByPanelLayout.createSequentialGroup()
                .add(dateRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(groupRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(destinationRadioButton))
        );

        graphPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Graph"));
        rangeList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Number of calls", "Call Duration" }));

        dataList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Per Hour", "Per Day", "Per Month", "Per Group" }));

        displayGraphButton.setText("Display Graph");
        displayGraphButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                displayGraphButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout graphPanelLayout = new org.jdesktop.layout.GroupLayout(graphPanel);
        graphPanel.setLayout(graphPanelLayout);
        graphPanelLayout.setHorizontalGroup(
            graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(graphPanelLayout.createSequentialGroup()
                .add(rangeList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(16, 16, 16)
                .add(dataList, 0, 118, Short.MAX_VALUE))
            .add(graphPanelLayout.createSequentialGroup()
                .add(displayGraphButton)
                .addContainerGap(150, Short.MAX_VALUE))
        );
        graphPanelLayout.setVerticalGroup(
            graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(graphPanelLayout.createSequentialGroup()
                .add(graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(rangeList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(dataList, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(displayGraphButton))
        );

        usagePanel.setLayout(new java.awt.BorderLayout());

        usagePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Usage Overview"));

        org.jdesktop.layout.GroupLayout cdrGraphPanelLayout = new org.jdesktop.layout.GroupLayout(cdrGraphPanel);
        cdrGraphPanel.setLayout(cdrGraphPanelLayout);
        cdrGraphPanelLayout.setHorizontalGroup(
            cdrGraphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(cdrGraphPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(cdrGraphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(usagePanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .add(graphPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(groupByPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        cdrGraphPanelLayout.setVerticalGroup(
            cdrGraphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(cdrGraphPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(groupByPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(graphPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(usagePanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 223, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        CDR_Border.add(cdrGraphPanel, java.awt.BorderLayout.EAST);

        Border.addTab("tab2", CDR_Border);

        getContentPane().add(Border, java.awt.BorderLayout.CENTER);

        opsMenu.setMnemonic('O');
        opsMenu.setText("Operations");
        opsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opsMenuActionPerformed(evt);
            }
        });

        addACL.setMnemonic('A');
        addACL.setText("Add");
        addACL.setToolTipText("Adds a call restriction");
        addACL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addACLActionPerformed(evt);
            }
        });

        opsMenu.add(addACL);

        editACL.setMnemonic('e');
        editACL.setText("Edit");
        editACL.setToolTipText("Edit Restriction");
        editACL.setEnabled(false);
        editACL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editACLActionPerformed(evt);
            }
        });

        opsMenu.add(editACL);

        removeACL.setText("Remove");
        removeACL.setToolTipText("Removes a call restriction");
        opsMenu.add(removeACL);

        opsMenu.add(opsSeparator);

        configGroups.setMnemonic('G');
        configGroups.setText("Groups");
        configGroups.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configGroupsActionPerformed(evt);
            }
        });

        opsMenu.add(configGroups);

        configPhones.setMnemonic('P');
        configPhones.setText("Phones");
        configPhones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configPhonesActionPerformed(evt);
            }
        });

        opsMenu.add(configPhones);

        configRestrictions.setMnemonic('R');
        configRestrictions.setText("Restrictions");
        configRestrictions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configRestrictionsActionPerformed(evt);
            }
        });

        opsMenu.add(configRestrictions);

        opsMenu.add(opsSeparator2);

        exitItem.setMnemonic('X');
        exitItem.setText("Exit");
        exitItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitItemActionPerformed(evt);
            }
        });

        opsMenu.add(exitItem);

        saveItem.setText("Create Conf Files");
        saveItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveItemActionPerformed(evt);
            }
        });

        opsMenu.add(saveItem);

        Menu.add(opsMenu);

        helpMenu.setMnemonic('H');
        helpMenu.setText("Help");
        helpIndex.setMnemonic('H');
        helpIndex.setText("Help Contents");
        helpMenu.add(helpIndex);

        helpMenu.add(helpSeparator);

        helpAbout.setMnemonic('B');
        helpAbout.setText("About");
        helpAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpAboutActionPerformed(evt);
            }
        });

        helpMenu.add(helpAbout);

        Menu.add(helpMenu);

        setJMenuBar(Menu);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void saveItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveItemActionPerformed
        Restrictions r = 
                new Restrictions (Settings.userName, Settings.password,
                Settings.IP,Settings.database);
        Groups g = new Groups (Settings.userName, Settings.password, 
                Settings.IP, Settings.database);
        Phones p = new Phones (Settings.userName, Settings.password, 
                Settings.IP, Settings.database);
        SoftPhones s =
                new SoftPhones (Settings.userName, Settings.password,
                Settings.IP,Settings.database);
        AccessControlList ACL = 
                new AccessControlList (Settings.userName,
                Settings.password, Settings.IP,Settings.database);
        
        AccessControlElement [] Elements = ACL.GetData ();
        String location = "/etc/asterisk/";
        
        if (Settings.isWindows)
            location = "c:\\";
        
        ConfigurationWriter.CreateExtensionsFile (
                Elements, r, s.GetData (),
                p.GetData (), location+"users_extensions.conf");
        ConfigurationWriter.CreateSIPFile (s.GetData (), location + 
                "users_sip.conf");
        
        JOptionPane.showMessageDialog (this, "Configuration Created. "
                +"Please RELOAD Asterisk");
    }//GEN-LAST:event_saveItemActionPerformed
    
    private void displayGraphButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_displayGraphButtonActionPerformed
        String range  = (String) rangeList.getSelectedItem ();
        String domain = (String) dataList.getSelectedItem ();
        
        String title = range.toLowerCase ()+" "+domain.toLowerCase ();
        char [] title_char = title.toCharArray ();
        
        title_char[0] = Character.toUpperCase (title_char[0]);
        
        int [] range_data = {1,2,3,4,5};
        String [] domain_data = {"6", "7", "8", "9", "10"};
        
        new GraphWindow (this, new String (title_char), range, 
                domain.substring (3), range_data, domain_data).setVisible (true);
    }//GEN-LAST:event_displayGraphButtonActionPerformed
    
    private String [] getDomain (String domain) {
        if (domain.equals ("Per Hour")) {
            String [] ret = {   "am","am","am","am","am","am","am",
            "am","am", "am","am","am",
            "pm","pm","pm","pm","pm","pm","pm","pm","pm","pm","pm",
            "pm"};
            return ret;
        } else if (domain.equals ("Per Day")) {
            String [] ret = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
            "Sun"};
            return ret;
        } else if (domain.equals ("Per Month")) {
            String [] ret  = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul",
            "Aug", "Sep", "Oct", "Nov", "Dec"};
            return ret;
        } else if (domain.equals ("Per Group")) {
            //TODO: Get a list of the groups from the database
            String [] ret = {"none"};
            return ret;
        } else {
            String [] ret = {"none"};
            return ret;
        }
    }
    private void editACLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editACLActionPerformed
        //TODO: Insert edit code
        new EditACLInterface (this, true).setVisible (true);
    }//GEN-LAST:event_editACLActionPerformed
    
    private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed
        new HelpAbout (this, true).setVisible (true);
    }//GEN-LAST:event_helpAboutActionPerformed
    
    private void exitItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitItemActionPerformed
        restrictionInterface.dispose ();
        phonesInterface.dispose ();
        groupsInterface.dispose ();
        dispose ();
        System.exit (0);
    }//GEN-LAST:event_exitItemActionPerformed
    
    private void addACLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addACLActionPerformed
        new NewACLInterface (this, true).setVisible (true);
    }//GEN-LAST:event_addACLActionPerformed
    
    private void configRestrictionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configRestrictionsActionPerformed
        restrictionInterface.setVisible (true);
    }//GEN-LAST:event_configRestrictionsActionPerformed
    
    private void configPhonesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configPhonesActionPerformed
        phonesInterface.setVisible (true);
    }//GEN-LAST:event_configPhonesActionPerformed
    
    private void configGroupsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configGroupsActionPerformed
        groupsInterface.setVisible (true);
    }//GEN-LAST:event_configGroupsActionPerformed
    
    private void opsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opsMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_opsMenuActionPerformed
    
    // <editor-fold defaultstate="collapsed" desc=" Main Function and Declarations ">
    /**
     * @param args the command line arguments
     */
    public static void main (String args[]) {
        java.awt.EventQueue.invokeLater (new Runnable () {
            public void run () {
                new ConfigurationInterface ().setVisible (true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable ACL_Table;
    private javax.swing.JTabbedPane Border;
    private javax.swing.JMenuBar Menu;
    private javax.swing.JMenuItem addACL;
    private javax.swing.JPanel cdrGraphPanel;
    private javax.swing.JTable cdrTable;
    private javax.swing.JScrollPane cdrTablePanel;
    private javax.swing.JMenuItem configGroups;
    private javax.swing.JMenuItem configPhones;
    private javax.swing.JMenuItem configRestrictions;
    private javax.swing.JComboBox dataList;
    private javax.swing.JRadioButton dateRadioButton;
    private javax.swing.JRadioButton destinationRadioButton;
    private javax.swing.JButton displayGraphButton;
    private javax.swing.JMenuItem editACL;
    private javax.swing.JMenuItem exitItem;
    private javax.swing.ButtonGroup graphButtonGroup;
    private javax.swing.JPanel graphPanel;
    private javax.swing.JPanel groupByPanel;
    private javax.swing.JRadioButton groupRadioButton;
    private javax.swing.JMenuItem helpAbout;
    private javax.swing.JMenuItem helpIndex;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenu opsMenu;
    private javax.swing.JComboBox rangeList;
    private javax.swing.JMenuItem removeACL;
    private javax.swing.JMenuItem saveItem;
    private javax.swing.JScrollPane tableScroll;
    private javax.swing.JPanel usagePanel;
    // End of variables declaration//GEN-END:variables
    // </editor-fold>
}
